package edu.ufrj.pesc.softwaregraph;

import java.util.*;

public class SoftwareGraph {

	private Vector<SoftwareGraphNode> nodes;
	private Vector<SoftwareGraphEdge> edges;
	
	public SoftwareGraph(){
		nodes = new Vector<SoftwareGraphNode>();
		edges = new Vector<SoftwareGraphEdge>();
	}
	
	/**
	    * Are there any verticies in the graph
	    * @return true if there are no verticies in the graph
	    */ 
	   public boolean isEmpty()
	   {
	      return nodes.size() == 0;
	   }

	   public void addNode(SoftwareGraphNode node)
	   {
		   nodes.add(node);
	   }
	   
	   public void removeNode(SoftwareGraphNode node)
	   {
		   nodes.remove(node);
	   }

	   public int size()
	   {
	      return nodes.size();
	   }	  
	   
	   public boolean addEdge(SoftwareGraphNode from, SoftwareGraphNode to)
	   {
	      SoftwareGraphEdge ed = new SoftwareGraphEdge(from, to);
	      if (from.findEdge(to) != null)
	         return false;
	      else
	      {
	         from.addEdge(ed);
	         to.addEdge(ed);
	         edges.addElement(ed);
	         return true;
	      }
	   }	   
	   
	   public void pruneFST()
	   {
		   
	   }
	
	   public String toString()
	   {
	      StringBuffer tmp = new StringBuffer("Graph[");
	      for (int i = 0; i < nodes.size(); i++)
	      {
	    	  SoftwareGraphNode v = (SoftwareGraphNode) nodes.elementAt(i);
	         tmp.append(v);
	      }
	      tmp.append(']');
	      return tmp.toString();
	   }	   
	   
}
